BTSelector = BTComposite:New()

local this = BTSelector
this.name = "Selector Task"

function this:New()
	local o = {}
	setmetatable(o, self)
	self.__index = self
	o.childTasks = {}
	return o
end

function this:OnUpdate()
	if (not self:HasChild()) then
		return BTTaskStatus.Failure
	end
	if (not self.currentChildTask) then
		self.currentChildTask = self:GetNextChild()
		if (not self.currentChildTask) then
			self.executionStatus = BTTaskStatus.Failure
			return BTTaskStatus.Failure
		end
	end
	while (self.currentChildTask) do
		self.executionStatus = self.currentChildTask:OnUpdate()
		if (self.executionStatus == BTTaskStatus.Success) then --结束
			self:Reset()
			self.executionStatus = BTTaskStatus.Success
			return BTTaskStatus.Success
		elseif (self.executionStatus == BTTaskStatus.Running) then --下一帧继续执行
			self.executionStatus = BTTaskStatus.Running
			return BTTaskStatus.Running
		else --继续执行下一节点
			self.currentChildTask = self:GetNextChild()
		end
	end
	--所有节点执行完毕
	self.executionStatus = BTTaskStatus.Failure
	--self:Reset()
	return BTTaskStatus.Failure
end